package io.modifier.basic.ext

import io.modifier.basic.core.log.logx.LogX
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch

private val handler = CoroutineExceptionHandler { _, exception ->
    // Handles exceptions that occur within coroutines
    exception.message?.let { LogX.tag("coroutineExt").d(it) }
}

// Manages the execution of tasks within a coroutine scope
fun CoroutineScope.safeLauncher(block: suspend CoroutineScope.() -> Unit): Job {
    return launch(handler, block = block)
}
